package cn.com.yusys.yusp.admin.service;

import cn.com.yusys.yusp.admin.domain.AdminSmDataFilter;
import cn.com.yusys.yusp.admin.repository.mapper.AdminSmDataFilterMapper;
import cn.com.yusys.yusp.commons.mapper.CommonMapper;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.util.DateUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminSmDataFilterService extends CommonService {
	@Autowired
	private AdminSmDataFilterMapper mapper;

	@SuppressWarnings("rawtypes")
    @Override
	protected CommonMapper getMapper() {
		return this.mapper;
	}

	@Override
	public int insert(Object record) {
		AdminSmDataFilter adminSmDataFilter = (AdminSmDataFilter) record;
		adminSmDataFilter.setLastChgDt(DateUtil.formatDateByDef());
		adminSmDataFilter.setLastChgUsr("admin");
		return this.insert(getMapper(), record);
	}

	public int deletes(String id) {
		return this.mapper.deleteByPrimaryKey(id);
	}

	/*
	 * 重写 ，为支撑页面模糊查询
	 */
	@Override
	public <T> List<T> selectByModel(QueryModel model) {
		// 模糊条件
		if (model.getCondition().containsKey("filterName")) {
			model.getCondition().put("filterName", "%" + model.getCondition().get("filterName") + "%");
		}
		if (model.getCondition().containsKey("classDesc")) {
			model.getCondition().put("classDesc", "%" + model.getCondition().get("classDesc") + "%");
		}
		if (model.getCondition().containsKey("queryUrl")) {
			model.getCondition().put("queryUrl", "%" + model.getCondition().get("queryUrl") + "%");
		}

		return this.selectByModel(getMapper(), model);
	}

}
